/*
 * @Author: hongbin
 * @Date: 2023-10-12 15:08:30
 * @LastEditors: hongbin
 * @LastEditTime: 2023-10-18 10:22:11
 * @Description: Schema
 */
import { Schema } from "mongoose";

const {
  Types: { String, Number, ObjectId },
} = Schema;

export const PersonnelSchema = new Schema({
  // _id: ObjectId,
  roleIds: { type: [ObjectId], required: true },
  name: { type: String, required: true, unique: true },
  password: { type: String, required: true },
});

export const ProjectSchema = new Schema({
  title: { type: String, required: true },
  order: { type: Number, required: true },
  creator: { type: ObjectId, ref: "creator", required: true },
});

//设置自动插入的版本号名称 默认 __v
//每次有数组变动会自动 + 1 防止并发错误
//如果要针对所有字段都进行版本控制，需要使用mongoose的插件：mongoose - update -if-current
ProjectSchema.set("versionKey", "__v");

export const RoleSchema = new Schema({
  desc: { type: String, required: true },
  name: { type: String, required: true, unique: true },
});
